package com.rongke.web;

import com.rongke.commons.JsonResp;
import com.rongke.model.SystemParm;
import com.rongke.service.SystemParmService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @SystemParmController
 * @系统参数Controller
 * @version : Ver 1.0
 */

@RestController
@RequestMapping(value="/api/systemParm")
@Transactional
@CrossOrigin(origins = "*", maxAge = 3600)
public class SystemParmController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private SystemParmService systemParmService;

    /**
     * @添加系统参数
     * @param systemParm
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addSystemParm(@RequestBody SystemParm systemParm){
        log.debug("添加系统参数");
        systemParmService.insert(systemParm);
        return JsonResp.ok(systemParm);
    }

    /**
     * @修改系统参数
     * @param systemParm
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updateSystemParm(@RequestBody SystemParm systemParm){
        log.debug("修改系统参数");
        systemParmService.updateById(systemParm);
        return JsonResp.ok(systemParm);
    }
    /**
     * @根据id查找系统参数
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectSystemParm(Long id){
        log.debug("查找系统参数");
        SystemParm systemParm = systemParmService.selectById(id);
        return JsonResp.ok(systemParm);
    }

    /**
     * @根据条件查找系统参数
     * @param systemParm
     * @return 返回值JsonResp
     */
    @RequestMapping(value = "/selectByCondition", method = RequestMethod.POST)
    public JsonResp selectSystemParmByCondition(@RequestBody SystemParm systemParm){
        log.debug("根据条件查找系统参数");
        if(systemParm==null)
            return JsonResp.toFail("参数不能为空");
        List<SystemParm> systemParmList=systemParmService.selectByCondition(systemParm);
        return JsonResp.ok(systemParmList);
    }

}
